package com.mkr.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author mkr
 * @version V1.0
 * @Project BookApp
 * @Package ${PACKAGE_NAME}
 * @Description: ${TODO}
 * @Date 2022/5/17 10:22
 */
@WebServlet(name = "regist" , urlPatterns = "/registServlet")
public class RegistServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1、设置编码
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        //2、获取页面传入的参数
        String name = request.getParameter("name");

        //3、判断以及实现业务
        String result = null ;
        if (name.equals("root") || name.equals("admin")){
            //定义2表示该用户已经存在
            result = "2";
        }else {
            //定义该用户可以注册
            result = "1";
        }

        //4、通过响应写数据到页面
        response.getWriter().write(result);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
